package com.yingdong.centerserver.net.frager;

import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

public class CenterServerPacketDefragerNetty4 extends ByteToMessageDecoder{

	@Override
	protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
		if (buffer.readableBytes() < 8) {
			return;
		}

		int allLength = buffer.getInt(buffer.readerIndex());
		int dataLength = buffer.getInt(buffer.readerIndex() + 4);
		if (buffer.readableBytes() < allLength) {
			return;
		} else {
			ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(allLength);
			buffer.readBytes(buf, allLength);
			out.add(buf);
			return;
		}
	}

}
